<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>用户列表展现案例</title>
	</head>
	<body>
		<div id="app">
			<div align="center">
				<h3 align="center">用户新增</h3><br>
				<p>
					用户名称: <input type="text" name="name"/>
					用户年龄: <input type="text" name="age"/>
					用户性别: <input type="text" name="sex"/>
					<button>新增</button>
				</p>
			</div>
			<hr />
			<div align="center">
				<h3 align="center">用户修改操作</h3><br>
				<p>
						用户ID号: <input type="text" name="id" disabled/>
						用户名称: <input type="text" name="name"/>
						用户年龄: <input type="text" name="age"/>
						用户性别: <input type="text" name="sex"/>
						<button>修改</button>
				</p>
			</div>
			<h1 align="center">用户列表展现案例</h1>
			<table align="center" border="1px" width="80%">
				<tr align="center">
					<td>ID编号</td>
					<td>姓名</td>
					<td>年龄</td>
					<td>性别</td>
					<td>操作</td>
				</tr>
				<tr align="center" v-for="user in userList">
					<td v-text="user.id"></td>
					<td v-text="user.name"></td>
					<td v-text="user.age"></td>
					<td v-text="user.sex"></td>
					<td>
						<button>修改</button>
						<button @click="deleteUser(user)">删除</button>
					</td>
				</tr>
				
			</table>
		</div>
		
		<script src="../js/axios.js"></script>
		<script src="../js/vue.js"></script>
		<script>
			//为axios执行前缀
			axios.defaults.baseURL="http://localhost:8090"

			const app = new Vue({
				el: "#app",
				data: {
					//3.定义数据列表
					userList: [],
					adduser:{
						
					}
				},
				methods: {
					//2.定义获取列表数据的函数
					async getUserList(){
						let {data: result} = await axios.get("/axios/findAll")
						//console.log(result)
						//将ajax返回值传递给Vue
						this.userList = result
					},
					async deleteUser(user){
						let {data:result} = await axios.delete("/axios/deleteUser?id="+user.id)
						user = {}
						this.getUserList()
						
					}
				},
				mounted(){
					//1利用生命周期函数调用getUser函数
					this.getUserList()
				}
			})
			
		</script>
	</body>
</html>

